package com.wr.recruit.service.utils;


import java.io.File;
import java.io.IOException;

public class FileUtils {

    public static void deleteFile(String destFileName) throws Exception {
        File file = new File(destFileName);
        if(file.exists())
            if(!file.delete()){
                throw new Exception();
            }
    }

    public static void createFile(String destFileName) throws Exception {
        File file = new File(destFileName);
        if(file.exists()) {
            if(!file.delete()){
                throw new Exception();
            }
        }
        if (destFileName.endsWith(File.separator)) {
            if(!file.mkdirs()){
                throw new Exception();
            }
            return;
        }
        //判断目标文件所在的目录是否存在
        if(!file.getParentFile().exists()) {
            //如果目标文件所在的目录不存在，则创建父目录
            if(!file.getParentFile().mkdirs()) {
                throw new Exception();
            }
        }
        //创建目标文件
        try {
            if (!file.createNewFile()) {
                throw new Exception();
            }
        } catch (IOException e) {
            throw new Exception();
        }
    }
}
